package com.you.concurrent.thread.join;

public class ThreadJoinDemo {

    public static void main(String[] args) throws InterruptedException {

        Thread t1 = new Thread(() -> {
            System.out.println("---------excute thread-1 start------");
            try {
                Thread.sleep(2000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("---------excute thread-1 end------");
        });
        Thread t2 = new Thread(() -> {
            System.out.println("---------excute thread-2 start------");
            try {
                t1.join();
                Thread.sleep(1L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("---------excute thread-2 end------");
        });
        t1.start();
        t2.start();
        t2.join();
        System.out.println("---------excute main thread------");
    }
}
